<?php

namespace App\Http\Controllers;

use App\Service\SaleDetailService;
use Illuminate\Routing\Controller as BaseController;

class IndexController extends BaseController
{
    public function index(){


        $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
        $endToday=mktime(0,0,0,date('m'),31+1,date('Y'))-1;

        //php获取昨日起始时间戳和结束时间戳
    	$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
    	$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;

    	$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
    	$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));

        $arr_toMonth = SaleDetailService::getCountInfoBySaleTime($beginThismonth, $endThismonth);
        $arr_toDay = SaleDetailService::getCountInfoBySaleTime($beginToday, $endToday);
        $arr_yesterday = SaleDetailService::getCountInfoBySaleTime($beginYesterday, $endYesterday);

        $arr_saleList = SaleDetailService::getCountInfoGroupBySaleTime($beginThismonth, $endThismonth);
        if ($arr_saleList){
            $arr_saleList = $arr_saleList->toArray();
            $arr_dateList = array_column($arr_saleList, 'sale_date');
            $arr_countList = array_column($arr_saleList, 'count');
            $arr_profitSum = array_column($arr_saleList, 'profit_sum');
            $arr_salePriceSum = array_column($arr_saleList, 'sale_price_sum');
        }else{
            $arr_dateList = [];
            $arr_countList = [];
            $arr_profitSum = [];
            $arr_salePriceSum = [];
        }
        return view('index/indexv5',[
            'todayCountInfo' =>$arr_toDay,
            'yesterdayCountInfo' =>$arr_yesterday,
            'toMonthCountInfo' =>$arr_toMonth,
            'dateList' => $arr_dateList,
            'countList' =>$arr_countList,
            'profitSum' =>$arr_profitSum ,
            'salePriceSum' =>$arr_salePriceSum,
        ]);
      //  return view('index/index');
    }

    public function countInfo(){
        return view('index/countInfo');
    }
}
